package com.fowo.api.user.model;

import com.fowo.api.sys.entity.SysUser;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;

/*
 * 用户信息 UserDetails 包装
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class SysUserDetails extends SysUser implements UserDetails {

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return getLoginFailUnlockTime() == null || getLoginFailUnlockTime().before(new Date());
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return !getIsDisabled();
    }
}
